import { Component, OnInit, Input, ViewChild, EventEmitter, Output } from '@angular/core';
import { HttpService } from 'lbf';

@Component({
  selector: 'lbAAC001',
  templateUrl: './lbAAC001.html'
})
export class LbAAC001Component implements OnInit {

  options = [];
  dataAAC001 = "";
  isLoad = false;
  
  constructor(private lbs: HttpService) { }
  

  @Output() changed =new EventEmitter<string>();

  @Input() set value(val: any) {

    this.dataAAC001 = val;

  }

  get value(): any {
    return this.getAAC001(this.dataAAC001);
  }
  ngOnInit(): void {

  }
   
  onclick(val:string){
    if(val)
      {
        this.queryData(val);
      }
  }

  onInput(event:KeyboardEvent,val:string)
  {
    if(event.key==="Enter") 
    {
  
      if(val)
      {
        this.queryData(val);
      }
      
    }
    else if(event.key==="ArrowUp"||event.key==="ArrowDown")
    {

    }
    else
    {
      this.options = [];
    }
    
    
  }

  queryData(val: string) {
    console.log('查询==》' + val);
    this.isLoad = true;
    this.lbs.lbservice('grsy_data', { para: val, page: { 'PAGESIZE': 10, 'PAGEIDX': 1 } }).then(resdata => {
       // this.isLoading = false;
       this.isLoad = false;
      if (resdata.code < 1) {
        // this.msgSrv.error(resdata.errmsg);
        console.log('查询结果1==》' + resdata);
        this.options = [];
      }
      else {
        if (resdata.page.COUNT === 0) {
          this.options = [];
        }
        else if (resdata.page.COUNT === 1) {
          // 直接赋值
          this.options = resdata.message.list;
           this.dataAAC001 = this.options[0].TEXT;
           this.options = [];
        }
        else {
          this.options = resdata.message.list;
          console.log('----');
          // this.isOptionVisible = true;
        }


      }

    });
    // this.options = [{AAC001:'00230122',TEXT:"00230122 - 张三丰 - 330124198201230314"},{AAC001:'00230123',TEXT:"00230123 | 李四友 | 330124197201230322"},{AAC001:'00230123',TEXT:"00230123 | 李四友 | 330124197201230322"}];
    
  }

  reset(value:string) {
    this.dataAAC001 = value;
  }


  setvalue(value:string) {
    if (!value)
      this.dataAAC001 = null;

    this.dataAAC001 = value;
  }

  change(value:string):void{
    this.changed.emit(this.getAAC001(value));
  }

  getAAC001(value:string):string{

    return value.split(' - ')[0];
  }
}